﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Project1.Common;
using System.Collections;
using HalconDotNet;
using System.Windows;
namespace Project1.Element
{
    public class Output
    {
        private string itemName;
        private List<Circle> circle = null;
        private List<Point> point = null;
        private List<Line> line =null;
        private List<double> distance = null;
        private int type;
        private double angle;
        private Hashtable args;
        private HObject regions;


        public Output()
        {
            circle = new List<Circle>();
            point = new List<Point>();
            line =new List<Line>();
            distance = new List<double>();
        }
        public Output(Output output)
        {
            if(output.regions != null)
            regions = new HObject(output.Regions);
            itemName = output.itemName;
            type = output.type;
            if(output.type == ConstValue.CIRCLE)
            {
                this.circle = new List<Circle>();
                foreach (var c in output.circle)
                {
                    this.circle.Add(new Circle(c));
                }

            }
            else if(output.type == ConstValue.POINT)
            {
                this.point = new List<Point>();
                foreach (var p in output.point)
                {
                    this.point.Add(new Point(p));
                }
            }
            else if(output.type == ConstValue.LINE)
            {
                this.line = new List<Line>();
                foreach (var l in output.line)
                {
                    this.line.Add(new Line(l));
                }
            }
            else if(output.type == ConstValue.ANGLE)
            {
                this.angle = output.angle;
            }
            else if(output.type == ConstValue.DISTANCE)
            {
                this.distance = new List<double>();
                foreach (var d in output.distance)
                {
                    this.distance.Add(d);
                }
            }
           
        }
        public Output(Circle circle,int type)
        {
            this.circle = new List<Circle>();
            this.circle.Add(new Circle(circle));
            regions = new HObject(circle.Region);
            this.type = type;
        }

        public Output(Line line, int type)
        {
            this.line = new List<Line>();
            this.line.Add(new Line(line));
            regions = new HObject(line.Region());
            this.type = type;
        }

        public Output(Point point, int type)
        {
            this.point = new List<Point>();
            this.point.Add(new Point(point));
            regions = new HObject(point.Region);
            this.type = type;
        }


        public Output(List<Point> points, int type)
        {
            regions = null;
            point = new List<Point>();
            foreach (var p in points)
            {
                this.point.Add(new Point(p));
                if(regions == null)
                {
                    regions = new HObject(p.Region);
                }
                else
                {
                    regions = regions.ConcatObj(p.Region);
                }
                
            }
            this.type = type;
        }

        public Output(double[] values,int type)
        {
            this.distance = new List<double>();
            foreach (var dist in values)
            {
                this.distance.Add(dist);
                
            }
            this.type = type;
        }

        public List<double> Dists { get { return distance; } }
        
        public double Angle
        {
            get { return angle; }
        }


        public void DispROI(HTuple windowHandle)
        {
            HTuple len;
            if(type != ConstValue.DISTANCE&&type != ConstValue.ANGLE)
            {
                HOperatorSet.CountObj(regions, out len);
                for (int i = 1; i < len; i++)
                {
                    HObject selectedObj = null;
                    HOperatorSet.SelectObj(regions, out selectedObj, i);
                    HOperatorSet.DispObj(selectedObj, windowHandle);
                }
            }
            else
            {
                foreach (var item in distance)
                {
                    //MessageBox.Show(""+item);
                }
              
                    //MessageBox.Show(""+angle);
             
                
            }
         
            
        }
        public Output(double value, int type)
        {
            this.type = type;
            if(type == ConstValue.ANGLE)
            {
                this.angle = value;
            }
            else
            {
                this.distance = new List<double>();
                this.distance.Add(value);

            }
          
        }
        public List<double> Distances(){  return distance;  }
        public List<Circle> Cs(){ return circle;   }
        public List<Point> Ps(){  return point;   }
        public List<Line> Ls(){ return line; }

        public HObject Regions
        {
            get { return regions; }
            set
            {
                if (regions == null) return;
                if (regions != null)
                {
                    regions.Dispose();
                }
                regions = new HObject(value);
            }

        }
        public int Type
        {
            get { return type; }
            set { type = value; }
        }

        public double A()
        {
            return angle; 
        }
        public double Distance()
        { 
            if(distance!=null) return distance.First(); 
            return 0;
        }
        public Circle C ()
        { 
            if (circle == null) return null; 
            return circle.First(); 
         }
        public Point P()
        {
            if (point == null) return null; return point.First(); 
        }
        public Line L() 
        { 
             if (line == null) return null; return line.First(); 
        }

        public string ItemName 
        {
            get { return itemName; }
            set { itemName = value; }
        }

        public void setType(int type)
        {
            this.type = type;
        }

        public override string ToString()
        {
            return "类型为" + type + ",元素名为" + itemName;
        }
    }
}
